import java.io.*;
import java.net.Socket;

public class SocketClient1 {
    static String name= "小红:";
    static Socket socket;
    static {
        try {
            socket = new Socket("localhost", 9999);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args){
        Thread s = new Thread(new send());
        Thread r =new Thread(new receive());
        s.start();
        r.start();
    }
    static class send extends Thread{
        public void run(){
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            while (true){
                try {
                    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
                    out.writeUTF(name+reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                    break;
                }
            }

        }
    }
    static class receive extends Thread{
        public void run(){
            while (true){
                try {
                    DataInputStream input = new DataInputStream(socket.getInputStream());
                    System.out.println(input.readUTF());
                } catch (IOException e) {
                    e.printStackTrace();
                    break;
                }
            }
        }
    }
}
